package jaxb;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

public class Object2Xml {

	public static void main(String[] args) {
		
		Customer customer = new Customer();
		customer.setId(100);
		customer.setName("mkyong");
		customer.setAge(29);
		
		CustList custList = new CustList();
		List<Customer> list = new ArrayList<Customer>();
		list.add(customer);
		custList.setList(list);
		try {
			File file = new File("d:\\file.xml");
			JAXBContext jaxbContext = JAXBContext.newInstance(CustList.class);  
			Marshaller jaxbMarshaller = jaxbContext.createMarshaller();  
			// output pretty printed  
			jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);  
			jaxbMarshaller.marshal(customer, file);  
			jaxbMarshaller.marshal(customer, System.out);  
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
